package com.app.designpatternslearn.behavior.mediatorpattern.code

class Node(private val mediator: Mediator) : AbstractNode {

    var name: String? = null
        set(value) {
            if (value != null) {
                mediator.addNode(value, this)
            }
            field = value
        }

    override fun sendMessage(to: String, message: String) {
        mediator.sendMessage(name!!, to, message)
    }


    override fun receiveMessage(from: String, message: String) {
        println("我是 $name ,接受到 $from 给我发的一条消息：$message")
    }

}